//
//  LJJGoodsListViewController.m
//  shopTest
//
//  Created by 梁佳佳 on 2016/11/21.
//  Copyright © 2016年 梁佳佳. All rights reserved.
//

#import "LJJGoodsListViewController.h"
#import "LJJGoodsListTopButtonView.h"
#import "LJJGoodsListCollectionView.h"
#import "LJJGoodsDetailViewController.h"

@interface LJJGoodsListViewController ()

@property (strong, nonatomic) LJJGoodsListTopButtonView *topButtonView;    /** 顶部的按钮view **/
@property (strong, nonatomic) LJJGoodsListCollectionView *collectionView;    /** 商品列表 **/

@end

@implementation LJJGoodsListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.edgesForExtendedLayout = 0;
    [self configUI];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}
- (void)configUI
{
    [self.view addSubview:self.topButtonView];
    [self.view addSubview:self.collectionView];
    __weak typeof(self) weakSelf = self;
    [_collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(weakSelf.view);
        make.top.equalTo(weakSelf.topButtonView.mas_bottom);
    }];
}

#pragma mark -
#pragma mark - lazy method

- (LJJGoodsListTopButtonView *)topButtonView
{
    if (!_topButtonView) {
        _topButtonView = [[LJJGoodsListTopButtonView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 30)];
    }
    return _topButtonView;
}
- (LJJGoodsListCollectionView *)collectionView
{
    if (!_collectionView) {
        UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
        flowLayout.itemSize = CGSizeMake((WIDTH - 10) / 2, (WIDTH - 10) / 2 / 0.725);
        _collectionView = [[LJJGoodsListCollectionView alloc] initWithFrame:CGRectMake(0, 0, 0, 0) collectionViewLayout:flowLayout];
        _collectionView.backgroundColor = MAINCOLOR;
        _collectionView.goodsListArray = self.goodsListArray;
        __weak typeof(self) weakSelf = self;
        _collectionView.selectCollectionBlock = ^(NSString *goodsID){
            LJJGoodsDetailViewController *detailVC = [[LJJGoodsDetailViewController alloc] init];
            detailVC.detailGoodsID = goodsID;
            [weakSelf.navigationController pushViewController:detailVC animated:YES];
        };
    }
    return _collectionView;
}

@end
